/*!
 * \file scope.h
 */
#ifndef _Cscope_H_83F03405_A559_4039_B076_8B5934A4623B_INCLUDED_
#define _Cscope_H_83F03405_A559_4039_B076_8B5934A4623B_INCLUDED_

#include <set>
#include <vector>
#include "Lang.h"

/*!
 * \brief символическое имя
 */
class CSymbol
{
public:
  enum Type
  {
    BOOL,
    INT,
    FLOAT,
    VECTOR,
    VARIABLE,
    LABEL,
  };

  Type m_type;
  int m_name;
  int m_sz;

  CSymbol(Type type,int name,int sz=0): m_type(type), m_name(name), m_sz(sz)
  {
  }

  bool operator <(const CSymbol& obj) const
  {
    return m_name<obj.m_name;
  }

  void print() const;

  static CSymbol makeByTypeAttr(int typeAttr,int name);
  static CSymbol makeTemp(Lang::Type type);
};


/*!
 * \brief кадр стека/область жизни переменных
 */
class CScope
{
  std::set<CSymbol> m_symbol;
  int m_undef;

public:
  CScope(): m_undef(0)
  {
  }

  void addDefinition(const CSymbol& s);
  void addReference(const CSymbol& s);
  const CSymbol& getSymbol(int name) const;

  void dump() const;
};//class Cscope

CScope& getFrame();

#endif //_Cscope_H_83F03405_A559_4039_B076_8B5934A4623B_INCLUDED_
